<template>
  <div>
<!--    添加按钮-->
    <div class="add" v-if="state1" v-show="state">
      <el-button type="primary" plain @click="add">添加按钮</el-button>
    </div>
<!--    添加弹出框-->
    <div v-if="!state1" class="add1" >
      <el-form ref="form" :model="sizeForm" label-width="80px" size="mini" style="width: 400px">
        <el-form-item label="轮椅名称:">
          <el-input v-model="sizeForm.name"></el-input>
        </el-form-item>
        <el-form-item label="所属医院:">
          <el-input v-model="sizeForm.name"></el-input>
        </el-form-item>
        <el-form-item label="轮椅数量:" style="width: 150px">
          <el-input v-model="sizeForm.name" ></el-input>
        </el-form-item>
        <el-form-item label="轮椅价格:" style="width: 150px">
          <el-input v-model="sizeForm.name" ></el-input>
        </el-form-item>
        <el-form-item label="轮椅图片:">
          <el-upload
              class="avatar-uploader"
              action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item size="large">
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button @click="quxiao1">取消</el-button>
        </el-form-item>
      </el-form>
    </div>

<!--    内容框-->
  <div v-show="state" v-if="state1">
  <el-table
      :data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
      style="width: 100%">
    <el-table-column
        align="center"
        label="轮椅类型"
        prop="date">
    </el-table-column>
    <el-table-column
        align="center"
        label="轮椅图片"
        prop="name">
    </el-table-column>
    <el-table-column
        align="center"
        label="所属医院"
        prop="name">
    </el-table-column>
    <el-table-column
        align="center"
        label="轮椅数量"
        prop="name">
    </el-table-column>
    <el-table-column
        align="center"
        label="轮椅租金价格"
        prop="name">
    </el-table-column>
    <el-table-column
        align="right">
      <template slot="header" slot-scope="scope">
        <el-input
            v-model="search"
            size="mini"
            placeholder="输入关键字搜索"/>
      </template>
      <template slot-scope="scope">
        <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">Edit</el-button>
        <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">Delete</el-button>
      </template>
    </el-table-column>
  </el-table>
  </div>
<!--    弹出框-->
    <div v-show="!state" class="add1">
      <el-form ref="form" :model="sizeForm" label-width="80px" size="mini" style="width: 400px">
        <el-form-item label="轮椅类型">
          <el-input v-model="sizeForm.name"></el-input>
        </el-form-item>
        <el-form-item label="所属医院">
          <el-input v-model="sizeForm.name"></el-input>
        </el-form-item>
        <el-form-item label="轮椅数量" style="width: 150px">
          <el-input v-model="sizeForm.name"></el-input>
        </el-form-item>
        <el-form-item label="租金价格" style="width: 150px" >
          <el-input v-model="sizeForm.name"></el-input>
        </el-form-item>
        <el-form-item label="轮椅图片:">
          <el-upload
              class="avatar-uploader"
              action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item size="large">
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button @click="quxiao">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name:'test2',
  data() {
    return {
      state:true,
      state1:true,
      sizeForm: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      search: ''
    }
  },
  methods: {
    handleEdit(index, row) {
      this.state = false
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    onSubmit() {
      console.log('submit!');
    },
    quxiao(){
      this.state = true
    },
    add(){
      this.state1 = false
    },
  //  图片上传
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
    quxiao1(){
      this.state1 = true
    }

  },
}
</script>
<style scoped>
.add{
  position:relative;
  top: 5px;
  left: 20px;
  width: 100px;
  height: 50px;
  z-index: 1000;
}
.add1{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
}

/*图片上传*/
.avatar-uploader{
  border: 1px dashed black;
}
.avatar-uploader .el-upload {
  border: 1px dashed black;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
